class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int n = nums.size();
        //lambda
        auto get = [&](int i) -> pair<int, int> {
            if (i == -1 || i == n) {
                return {0, 0};
            }
            return {1, nums[i]};
        };
        int left = 0;
        int right = n - 1;
        int res = -1;
        // 峰值必须是当前值大于左值并且大于右值
        while (left <= right) {
            int mid = (left + right) / 2;
            if (get(mid) > get(mid + 1) && get(mid) > get(mid - 1)) {
                res = mid;
                break;
            } else if (get(mid) < get(mid + 1)) {
                left = mid + 1;
            } else if (get(mid) < get(mid - 1)) {
                right = mid - 1;
            }
        }
        return res;
    }
};